package com.thon.service.project.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.thon.dao.project.ProjectShareDao;
import com.thon.dao.util.Page;
import com.thon.entity.project.ProjectAttention;
import com.thon.entity.project.ProjectShare;

import com.thon.service.project.ProjectShareService;

/**
 * @file ProjectShareServiceImpl.java
 * @author Zemo
 * @mail zemochen@gmail.com
 * @data 2013年11月18日 上午11:26:44
 * @description: TODO
 */
@Service
@Transactional
public class ProjectShareServiceImpl  implements ProjectShareService {
	
	@Autowired
	private ProjectShareDao projectShareDao;

	@Override
	public void add(ProjectShare projectShare) {
		
		projectShare.setClickCount(0);
		projectShareDao.save(projectShare);
	}

	@Override
	public ProjectShare getProjectShare(int projectShareId) {
		
		return projectShareDao.get(projectShareId);
	}

	@Override
	public Long countProjectShare(int projectId,int preferentialId) {
		if(projectId!=0)
		{
			return projectShareDao.countShare(projectId);
		}
		else if(preferentialId!=0)
		{
			return projectShareDao.countPreferentialShare(preferentialId);
		}
			
		else {
			return (long) 0;
		}
	}

	@Override
	public Page<ProjectShare> findProjectShareByUser(Integer userId,Integer method,
			Integer pageNo, Integer pageSize) {
		Page<ProjectShare> page=new Page<ProjectShare>();
		page.setPageNo(pageNo);
		page.setPageSize(pageSize);
		
		return projectShareDao.findProjectShareByUser(userId,method,page);
	}


}
